home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / pascal / flxkey.exe / RANDCODE.PAS < prev    next >
Pascal/Delphi Source File  |  1993-02-21  |  4KB  |  128 lines

  1.  
  2. (**********************************************************************)
  3. (* Simple program to build two random encryption-code strings, and    *)
  4. (* then save them to disk.                                            *)
  5. (**********************************************************************)
  6.  
  7. program Make_Random_Encryption_Codes;
  8.  
  9. type          (* 20 character string definition.                      *)
  10.   st_20 = string[20];
  11.  
  12. var           (* String index variable.                               *)
  13.   Index,
  14.  
  15.               (* Used to store the value of "ioresult".               *)
  16.   ErrorCode : byte;
  17.  
  18.               (* 2 encryption-code strings.                           *)
  19.   Ecode1,
  20.   Ecode2    : st_20;
  21.  
  22.               (* Temporary file varialble.                            *)
  23.   TempFile  : file;
  24.  
  25.               (* Main program execution block.                        *)
  26. BEGIN
  27.               (* Clear the encryption-code strings.                   *)
  28.   fillchar(Ecode1, sizeof(Ecode1), 0);
  29.   fillchar(Ecode2, sizeof(Ecode2), 0);
  30.  
  31.               (* Set the length byte for both encryption-code strings *)
  32.               (* to 20.                                               *)
  33.   Ecode1[0] := #20;
  34.   Ecode2[0] := #20;
  35.  
  36.               (* Ensure that the data will be random.                 *)
  37.   randomize;
  38.  
  39.               (* Assign random data to each of the encryption-code    *)
  40.               (* strings.                                             *)
  41.   for Index := 1 to 20 do
  42.     begin
  43.       Ecode1[Index] := chr(random(256));
  44.       Ecode2[Index] := chr(random(256))
  45.     end;
  46.  
  47.               (* Open first encryption-code string file.              *)
  48.   assign(TempFile, 'ECODE1.DAT');
  49.   {$I-}
  50.   rewrite(TempFile, 1);
  51.   {$I+}
  52.  
  53.               (* Check for errors.                                    *)
  54.   ErrorCode := ioresult;
  55.   if (ErrorCode <> 0) then
  56.     begin
  57.       writeln(' Error ', ErrorCode, ' opening "ECODE1.DAT" file.');
  58.       halt
  59.     end;
  60.  
  61.               (* Write first ecryption-code string to disk.           *)
  62.   writeln;
  63.   writeln(' Writing first encryption-code to disk.');
  64.   blockwrite(TempFile, Ecode1, succ(length(Ecode1)));
  65.  
  66.               (* Check for errors.                                    *)
  67.   ErrorCode := ioresult;
  68.   if (ErrorCode <> 0) then
  69.     begin
  70.       writeln(' Error ', ErrorCode,
  71.                                  ' writing data to "ECODE1.DAT" file.');
  72.       halt
  73.     end;
  74.  
  75.               (* Close first encryption-code string file.             *)
  76.   close(TempFile);
  77.  
  78.               (* Check for errors.                                    *)
  79.   ErrorCode := ioresult;
  80.   if (ErrorCode <> 0) then
  81.     begin
  82.       writeln(' Error ', ErrorCode, ' closing "ECODE1.DAT" file.');
  83.       halt
  84.     end;
  85.  
  86.               (* Open second encryption-code string file.             *)
  87.   assign(TempFile, 'ECODE2.DAT');
  88.   {$I-}
  89.   rewrite(TempFile, 1);
  90.   {$I+}
  91.  
  92.               (* Check for errors.                                    *)
  93.   ErrorCode := ioresult;
  94.   if (ErrorCode <> 0) then
  95.     begin
  96.       writeln(' Error ', ErrorCode, ' opening "ECODE2.DAT" file.');
  97.       halt
  98.     end;
  99.  
  100.               (* Write second ecryption-code string to disk.          *)
  101.   writeln;
  102.   writeln(' Writing second encryption-code to disk.');
  103.   blockwrite(TempFile, Ecode2, succ(length(Ecode2)));
  104.  
  105.               (* Check for errors.                                    *)
  106.   ErrorCode := ioresult;
  107.   if (ErrorCode <> 0) then
  108.     begin
  109.       writeln(' Error ', ErrorCode,
  110.                                  ' writing data to "ECODE2.DAT" file.');
  111.       halt
  112.     end;
  113.  
  114.               (* Close second encryption-code string file.            *)
  115.   close(TempFile);
  116.  
  117.               (* Check for errors.                                    *)
  118.   ErrorCode := ioresult;
  119.   if (ErrorCode <> 0) then
  120.     begin
  121.       writeln(' Error ', ErrorCode, ' closing "ECODE1.DAT" file.');
  122.       halt
  123.     end
  124.  
  125. END.
  126.  
  127.  
  128.